package cn.supermarket.controller;

import cn.supermarket.pojo.dto.AddOrderDTO;
import cn.supermarket.pojo.vo.PurchaseOrdersVO;
import cn.supermarket.pojo.vo.SimpleOrderVO;
import cn.supermarket.service.impl.OrderServiceImpl;
import cn.supermarket.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/order")
@Api(tags = "订单模块")
public class OrderController extends BaseController{
    @Autowired
    private OrderServiceImpl addOrderService;
    @PostMapping("/add")
    @ApiOperation("添加订单")
    public JsonResult<Void> addOrder( AddOrderDTO addOrderDTO){
        addOrderService.addOrder(addOrderDTO);
        return JsonResult.ok();
    }
    @PostMapping("/select/by-order-id")
    @ApiOperation("通过订单编号或者日期查询订单")
    public JsonResult<List<PurchaseOrdersVO>> selectOrder(Long id, Date startTime, Date endTime){
        List<PurchaseOrdersVO> list = addOrderService.selectOrderByIdOrByTime(id, startTime, endTime);
        return JsonResult.ok(list);
    }
    @GetMapping("/select/by-purchaser")
    @ApiOperation("通过采购商查询订单")
    public JsonResult<List<SimpleOrderVO>> selectOrderByPurchaser(String purchaser){
        List<SimpleOrderVO> simpleOrders = addOrderService.selectOrderByPurchaser(purchaser);
        return JsonResult.ok(simpleOrders);
    }
    @GetMapping("/update/display")
    @ApiOperation("修改订单是否可见")
    public JsonResult updateOrderIsDisplay(Long orderId,Integer isDisplay){
         addOrderService.updateOrderIsDisplay(orderId,isDisplay);
        return JsonResult.ok();
    }
    @GetMapping("/update/enable")
    @ApiOperation("修改订单是否锁定")
    public JsonResult updateOrderIsEnable(Long orderId,Integer isEnable){

        addOrderService.updateOrderIsEnable(orderId,isEnable);
        return JsonResult.ok();
    }
    @GetMapping("/update/cancel")
    @ApiOperation("修改订单是否作废")
    public JsonResult updateOrderIsCancel(Long orderId,Integer isCancel){
        addOrderService.updateOrderIsEnable(orderId,isCancel);
        return JsonResult.ok();
    }


}
